package com.lbj.mall.search.web;

import com.lbj.mall.common.utils.R;
import com.lbj.mall.search.entity.vo.SearchParams;
import com.lbj.mall.search.entity.vo.SearchResult;
import com.lbj.mall.search.service.MallSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class WebController {

    @Autowired
    MallSearchService searchService;

    @GetMapping({"/", "/list", "list.html"})
    public String index(SearchParams params, Model model) {
        SearchResult result = searchService.search(params);
        model.addAttribute("result",result);
        return "list";
    }

    @GetMapping("/search")
    @ResponseBody
    public R search(SearchParams params, Model model) {
        SearchResult result = searchService.search(params);
        model.addAttribute("result",result);
        return R.ok();
    }
}
